#include <tinx/printk.h>
#include <tinx/device.h>
#include <tinx/stdarg.h>
#include <tinx/vsprintf.h>
#include <tinx/assert.h>

static char buf[1024];

static void spin(char *name)
{
    printk("spinning in %s ...\n", name);
    while (1)
        ;
}

void assert_failure(char *condition, char *file, int line)
{
    printk(
        "\n-->assert(%s) failed!!!\n"
        "--> file: %s \n"
        "--> line: %d \n",
        condition, file, line);

    spin("assert_failure()");
}

void panic_spin(char *file, int line, char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);

    vsprintf(buf, fmt, args);

    va_end(args);

    printk(
        "\n!!! panic !!! \n"
        "--> %s          \n"
        "--> file: %s    \n"
        "--> line: %d    \n",
        buf, file, line);

    spin("panic()");
}